//
//  YBHomeAssetsTableViewCell.m
//  Nectar
//
//  Created by famer on 2023/11/7.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBHomeAssetsTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation YBHomeAssetsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        
        _logoImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_logoImageView];
        
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textColor = [UIColor hexColor:@"1E1E1E"];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.numberOfLines = 0;
        _nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self.contentView addSubview:_nameLabel];
        
        _balanceLabel = [[UILabel alloc] init];
        _balanceLabel.font = [UIFont systemFontOfSize:16];
        _balanceLabel.textColor = [UIColor hexColor:@"1E1E1E"];
        _balanceLabel.textAlignment = NSTextAlignmentLeft;
        _balanceLabel.numberOfLines = 0;
        _balanceLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self.contentView addSubview:_balanceLabel];

        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = kThemeSplitLineColor;
        [self.contentView addSubview:_lineView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.size.width;
    CGFloat height = self.contentView.size.height;

    self.logoImageView.frame = CGRectMake(0, 0, 30, 30);
    self.logoImageView.centerY = height*0.5;
    
    CGFloat balanceLabelWidth = [self.balanceLabel textBoundingSizeWithMaxSize:CGSizeMake(500, height)].width;
    self.balanceLabel.frame = CGRectMake(width-balanceLabelWidth, 0, balanceLabelWidth, height);
    self.balanceLabel.centerY = height*0.5;

    CGFloat nameLabelWidth = width-(self.logoImageView.right+10)-balanceLabelWidth;
    self.nameLabel.frame = CGRectMake(self.logoImageView.right+10, 0, nameLabelWidth, height);
    self.nameLabel.centerY = height*0.5;
    
    self.lineView.frame = CGRectMake(0, height-1, width, 1);
}

- (void)setData:(RevDataGetUserAccount *)item{
    NSString *url = [NSString stringWithFormat:@"%@",item.logo];
    [self.logoImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil options:SDWebImageAllowInvalidSSLCertificates];
    
    self.nameLabel.text = item.coinName;
    
    self.balanceLabel.text = [NSString stringWithFormat:@"%@",item.balance];
    
    [self setNeedsLayout];
    [self layoutIfNeeded];
}
@end
